import re


def func1(a):
    res = re.split('([*/])+', a)
    # print(res)
    count = len(res)
    while count > 2:
        for i in range(count):
            if res[i] == '*':
                result = float(res[i-1])*float(res[i+1])
                res[i+1] = str(result)
                del res[i-1:i+1]
                # print(res)
                break
            elif res[i] == '/':
                result = float(res[i-1])/float(res[i+1])
                res[i+1] = str(result)
                del res[i-1:i+1]
                # print(res)
                break
        count = len(res)
    return res[0]


a = '1-2*((60-30+(-40/5)*(9-2*5/3+7/3*99/4*2998+10*568/14))-(-4*3)/(16-3*2))'
print('the result:', eval(a))

a = a.replace(' ', '')
print(a)
res = re.findall(r'\(([-+*/0-9]+)\)', a)
print(res)

for exp in res:
    res1 = re.findall('[*/.0-9]+', exp)
    print('exp: ',exp)
    # print(res1)
    if len(res1) == 1:
        result = str(func1(res1[0]))
        print('res1[0]: ',res1[0])
        print('result:',result)
        res[res.index(exp)] = re.sub(res1[0].replace('*','\*'), result, exp)


print(res)
